package cn.demomaster.quickui_sample.ui.fragment.helper;

import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.demomaster.quickcompat.widget.layout.CompressLayout;

import cn.demomaster.quickrouter.fragment.QuickFragment;
import cn.demomaster.quickui.annotation.ActivityPager;
import cn.demomaster.quickui.annotation.ResType;
import cn.demomaster.quickui_sample.R;


/**
 * Squirrel桓
 * 2021/2/19
 */

@ActivityPager(name = "压缩布局", preViewClass = TextView.class, resType = ResType.Custome)
public class CompressLayoutFragment extends QuickFragment {

    Button btn_left;
    Button btn_top;
    Button btn_right;
    Button btn_bottom;
    Button btn_open;
    Button btn_close;
    CompressLayout compressLayout;
    ImageView iv_emtion;

    @NonNull
    @Override
    public View onGenerateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View mView = inflater.inflate(R.layout.fragment_layout_compress, null);
        return mView;
    }

    public void initView(View rootView) {
        btn_left = findViewById(R.id.btn_left);
        btn_top = findViewById(R.id.btn_top);
        btn_right = findViewById(R.id.btn_right);
        btn_bottom = findViewById(R.id.btn_bottom);
        btn_open = findViewById(R.id.btn_open);
        btn_close = findViewById(R.id.btn_close);
        compressLayout = findViewById(R.id.compressLayout);
        iv_emtion = findViewById(R.id.iv_emtion);
        getActionBarTool().getRightView().setVisibility(View.GONE);
        setTitle("压缩布局");
        // mContext.getCurrentFocus()
        compressLayout.setDuration(1000);
        btn_left.setOnClickListener(v -> compressLayout.setGravity(Gravity.LEFT));
        btn_top.setOnClickListener(v -> compressLayout.setGravity(Gravity.TOP));
        btn_right.setOnClickListener(v -> compressLayout.setGravity(Gravity.RIGHT));
        btn_bottom.setOnClickListener(v -> compressLayout.setGravity(Gravity.BOTTOM));
        btn_open.setOnClickListener(v -> compressLayout.showPanel());
        btn_close.setOnClickListener(v -> compressLayout.dissmissPanel());
        iv_emtion.setOnClickListener(v -> {
            if(compressLayout.isExpanded()){
                compressLayout.dissmissPanel();
            }else {
                compressLayout.showPanel();
            }
        });
    }

    // 如果是activity 当点击返回键时, 如果软键盘正在显示, 则隐藏软键盘并是此次返回无效
   /* @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            if (qdKeyboard.isShow()) {
                qdKeyboard.hideKeyboard();
                return false;
            }
            return super.onKeyDown(keyCode, event);
        }
        return super.onKeyDown(keyCode, event);
    }*/

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

}